package ai.mspbots.poc.es.processor;

import ai.mspbots.poc.db.entity.AbbreviationMap;
import ai.mspbots.poc.db.service.AbbreviationMapService;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;

import java.util.List;

public class AbbreviationMapper {
    // private static final Map<String, String> abbreviationMap = new HashMap<>();
    //
    // static {
    //     abbreviationMap.put("nt", "nextTicket");
    //     abbreviationMap.put("nt", "newTask");
    //     abbreviationMap.put("ok", "lucene");
    //     // 可以添加更多的映射
    // }

    private static final AbbreviationMapService abbreviationMapService = SpringUtil.getBean(AbbreviationMapService.class);

    public static String replaceAbbreviations(String input) {
        List<AbbreviationMap> abbreviationMaps = abbreviationMapService.list();
        for (AbbreviationMap abbreviationMap : abbreviationMaps) {
            if (StrUtil.equalsIgnoreCase(input, abbreviationMap.getOriginal())) {
                return abbreviationMap.getMapped();
            }
            // input = input.replace(abbreviationMap.getOriginal(), abbreviationMap.getMapped());
        }
        // for (Map.Entry<String, String> entry : abbreviationMap.entrySet()) {
        //     input = input.replace(entry.getKey(), entry.getValue());
        // }
        return input;
    }
}
